import Vue from 'vue'

export default {
    install(){
        Vue.directive('imgs', function(el, binding, vnode){
            let picPath = el.getAttribute('src'),
                domainList = [
                    'img.alicdn.com',
                    'erp-storage-img',
                    'wish.com'
                ],
                size = (binding.expression && binding.expression.split(',')) || [40, 40],
                suffix = '_' + size[0] + 'x' + size[1] + '.jpg';
            
            for(let i=0; i<domainList.length; i++){
                if(picPath.indexOf(domainList[i]) > -1){
                    switch(domainList[i]){
                        case 'wish.com':
                            //规则待定
                            break;
                        default:
                            el.setAttribute('src', el.getAttribute('src') + suffix);
                            break;
                    }
                }
            }
        });
    }
}